﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using QunYing.Model;
namespace QunYing.BLL
{
	/// <summary>
	/// Category
	/// </summary>
	public partial class Category
	{
		private readonly QunYing.DAL.Category dal=new QunYing.DAL.Category();
		public Category()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int 类别ID)
		{
			return dal.Exists(类别ID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(QunYing.Model.Category model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(QunYing.Model.Category model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int 类别ID)
		{
			
			return dal.Delete(类别ID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string 类别IDlist )
		{
			return dal.DeleteList(类别IDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public QunYing.Model.Category GetModel(int 类别ID)
		{
			
			return dal.GetModel(类别ID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public QunYing.Model.Category GetModelByCache(int 类别ID)
		{
			
			string CacheKey = "CategoryModel-" + 类别ID;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(类别ID);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (QunYing.Model.Category)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<QunYing.Model.Category> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<QunYing.Model.Category> DataTableToList(DataTable dt)
		{
			List<QunYing.Model.Category> modelList = new List<QunYing.Model.Category>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				QunYing.Model.Category model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new QunYing.Model.Category();
					if(dt.Rows[n]["类别ID"]!=null && dt.Rows[n]["类别ID"].ToString()!="")
					{
						model.类别ID=int.Parse(dt.Rows[n]["类别ID"].ToString());
					}
					if(dt.Rows[n]["经销商编号"]!=null && dt.Rows[n]["经销商编号"].ToString()!="")
					{
					model.经销商编号=dt.Rows[n]["经销商编号"].ToString();
					}
					if(dt.Rows[n]["类别名称"]!=null && dt.Rows[n]["类别名称"].ToString()!="")
					{
					model.类别名称=dt.Rows[n]["类别名称"].ToString();
					}
					if(dt.Rows[n]["类别图片"]!=null && dt.Rows[n]["类别图片"].ToString()!="")
					{
					model.类别图片=dt.Rows[n]["类别图片"].ToString();
					}
					if(dt.Rows[n]["父类别ID"]!=null && dt.Rows[n]["父类别ID"].ToString()!="")
					{
						model.父类别ID=int.Parse(dt.Rows[n]["父类别ID"].ToString());
					}
					if(dt.Rows[n]["显示顺序"]!=null && dt.Rows[n]["显示顺序"].ToString()!="")
					{
						model.显示顺序=int.Parse(dt.Rows[n]["显示顺序"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

